package com.vincent.kdp.Activity;

import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;

import com.vincent.baseapp.util.CommonUtil;
import com.vincent.kdp.PostUrl;
import com.vincent.kdp.R;
import com.vincent.kdp.js.GetGoodsDetailOperator;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class GetGoodsDetailActivity extends AppCompatActivity {

    @Bind(R.id.back_img)
    ImageView mBackImg;
    @Bind(R.id.toolbar_center_tv)
    TextView mToolbarCenterTv;
    @Bind(R.id.webView_goods)
    WebView webViewGoods;

    private String code;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_get_goods_detail);
        ButterKnife.bind(this);
        CommonUtil.showLoadingView(this);
        initView();
        initData();
    }
    private void initView() {
        mToolbarCenterTv.setText("申请调货");
        code=getIntent().getStringExtra("barCode");
        Log.i("code",code);
    }

    @SuppressLint({ "NewApi", "SetJavaScriptEnabled" })
    private void initData() {

        webViewGoods.addJavascriptInterface(new GetGoodsDetailOperator(GetGoodsDetailActivity.this,code),"GetGoodsDetail");

        String url= PostUrl.SERVICE_URL+"/H5/goodTransshipment/goodTransshipment.html";
        WebSettings mSettings= webViewGoods.getSettings();

        mSettings.setJavaScriptEnabled(true);
        mSettings.setAllowFileAccess(true);
        mSettings.setAllowFileAccessFromFileURLs(true);

        webViewGoods.setWebViewClient(new WebViewClient(){
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);

            }
            @Override
            public void onPageFinished(WebView view, String url) {
                CommonUtil.dismissLoadingView(GetGoodsDetailActivity.this);
                super.onPageFinished(view, url);
            }
        });
        webViewGoods.loadUrl(url);
    }

    @OnClick(R.id.back_img)
    public void onClick() {
        this.finish();
        overridePendingTransition(com.vincent.baseapp.R.anim.fragment_left_in, com.vincent.baseapp.R.anim.fragment_right_out);
    }
}
